#!/bin/bash

#########################################
# merge-performance.sh
# 将所有子目录中的 performance-report.txt 合并
#########################################

OUTPUT_FILE="performance-report.txt"
BASE_DIR="../output/problem3"

# 清空或创建目标文件
echo "" > "$OUTPUT_FILE"

# 遍历 ../output 下一级子目录
for dir in "$BASE_DIR"/*/; do
    # 目录名（作为 title）
    dirname=$(basename "$dir")
    
    report_file="${dir}/performance-report.txt"
    
    if [[ -f "$report_file" ]]; then
        echo "Processing: $dirname"

        {
            echo "### ${dirname}"
            echo "---"
            cat "$report_file"
            echo ""
            echo "---"
            echo ""
        } >> "$OUTPUT_FILE"
    else
        echo "Skipping: $dirname (no performance-report.txt)"
    fi
done

echo "Merged reports saved to $OUTPUT_FILE"
